import { BasicDecoder } from '../BasicDecoder';

export class FlightGearDecoder extends BasicDecoder {
  public decode(buffer: ArrayBuffer) {
    const TYPE_LIST = ["对地速度", "空速", "向下分速度", "向东分速度", "向北分速度", "升降速度", "指示速度", "真实速度", "俯仰角", "旋转角", "离地高度", "海拔高度", "经度", "纬度", "航向", "航向偏移度", "转弯速率", "滑动程度", "发动机是否运转", "发动机转速", "通讯电源按钮", "通讯音量", "通讯频道", "测距仪开关", "重力加速度",];

    let str: string = String.fromCharCode.apply(null, new Uint8Array(buffer)); //若str中含有,退出
    if (str.indexOf(",") != -1) {
      return null;
    }
    let strArr = str.split("\n");
    let recvDataMap = new Map();
    for (let i = 0;i < strArr.length; i++) {
      strArr[i] = strArr[i].trim();
      let num = Number(strArr[i]);
      recvDataMap.set(TYPE_LIST[i], num)
    }
    return recvDataMap;
  }
}

